<?php
class ArticlecatController extends QSource_System_Controller_Action{
        public function init(){
                $this->loadTemplate('default');
        }
        public function indexAction(){ 
                $this->_redirect('/');
        }
        public function detailAction(){
                $alias = $this->_request->getParam('alias','');
                if($alias=='')
                        $this->_redirect('/');
                $model = new Model_ArticleCat_ArticleCat();
                $item = $model->getItemAlias($alias);
                $this->view->itemCat = $item;
                $modelArticle = new Model_Article_Article();
                $data = $modelArticle->getItemsByCate($item['id']);
                $this->view->count = count($data);
                Zend_View_Helper_PaginationControl::setDefaultViewPartial(APPLICATION_PATH.'\modules\default\views\pagination.phtml');
                $pa = Zend_Paginator::factory($data);
                $pa->setItemCountPerPage(10);
                $current = $this->_request->getParam('page');
                $this->view->page = $current;
                $pa->setCurrentPageNumber($current);
                $this->view->data = $pa;
                $modelSite = new Model_SiteInfo_SiteInfo();
                $info = $modelSite->getItemId(1);
                $this->view->alias = $alias;
                $this->view->headMeta()->appendName('keywords', $item['web_keyword']);
                $this->view->headMeta()->appendName('description', $item['web_description']);
                $this->view->headTitle($item['name'].' - '.$info['name'],true);
        }
        public function listAction()
        {
                if ($this->_request->isPost()) {
                	$modelArticle = new Model_Article_Article();
                	$limit = $this->_request->getParam('limit','10');
                	$alias = $this->_request->getParam('alias','');
                	$model = new Model_ArticleCat_ArticleCat();
                	$item = $model->getItemAlias($alias);
                	$this->view->limit = $limit;
                	$data = $modelArticle->getItemsByCate($item['id']);
                	$this->view->count = count($data);
                	Zend_View_Helper_PaginationControl::setDefaultViewPartial(APPLICATION_PATH.'\modules\default\views\pagination.phtml');
                	$pa = Zend_Paginator::factory($data);
                	$pa->setItemCountPerPage(10);
                	$current = $this->_request->getParam('page');
                	$this->view->page = $current;
                	$pa->setCurrentPageNumber($current);
                	$this->view->data = $pa;
                }
                else
                {
                        return "Lỗi khi cập nhật dữ liệu.";
                }
                $this->_helper->layout->disableLayout();
        }
        public function videoAction()
        {
        	$model_video = new Model_Video_Video();
        	$data = $model_video->getAllIsActive();
        	$limit = 10;
        	if ($this->_request->isPost()) {
        		$limit = $this->_request->getParam('limit','10');
        	}
        	Zend_View_Helper_PaginationControl::setDefaultViewPartial(APPLICATION_PATH.'\modules\default\views\pagination.phtml');
        	$pa = Zend_Paginator::factory($data);
        	$pa->setItemCountPerPage($limit);
        	$current = $this->_request->getParam('page');
        	$this->view->page = $current;
        	$pa->setCurrentPageNumber($current);
        	$this->view->data = $pa;
        	$this->_helper->layout->disableLayout();
        }
}